//package com.utils.spring.shirospringboot;
//
//import org.apache.shiro.authc.AuthenticationException;
//import org.apache.shiro.authc.AuthenticationInfo;
//import org.apache.shiro.authc.AuthenticationToken;
//import org.apache.shiro.authc.SimpleAuthenticationInfo;
//import org.apache.shiro.authc.UnknownAccountException;
//import org.apache.shiro.authc.UsernamePasswordToken;
//import org.apache.shiro.authz.AuthorizationInfo;
//import org.apache.shiro.realm.AuthorizingRealm;
//import org.apache.shiro.subject.PrincipalCollection;
//import org.springframework.beans.factory.annotation.Autowired;
//
//import com.kyhd.dshp.manage.model.User;
//import com.kyhd.dshp.manage.service.UserService;
//
///**
// * 用户密码登录realm
// */
//public class UserPasswordRealm extends AuthorizingRealm {
//	@Autowired
//	private UserService userService;
//
//	@Override
//	public String getName() {
//		return LoginType.USER_PASSWORD.getType();
//	}
//
//	@Override
//	public boolean supports(AuthenticationToken token) {
//		if (token instanceof UserToken) {
//			return ((UserToken) token).getLoginType() == LoginType.USER_PASSWORD;
//		} else {
//			return false;
//		}
//	}
//
//	@Override
//	public void setAuthorizationCacheName(String authorizationCacheName) {
//		super.setAuthorizationCacheName(authorizationCacheName);
//	}
//
//	@Override
//	protected void clearCachedAuthorizationInfo(PrincipalCollection principals) {
//		super.clearCachedAuthorizationInfo(principals);
//	}
//
//	/**
//	 * 认证信息.(身份验证) : Authentication 是用来验证用户身份
//	 *
//	 */
//	@Override
//	protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken)
//			throws AuthenticationException {
//		UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
//		System.out.println("token="+token);
//		String name = token.getUsername();
//		// 从数据库获取对应用户名密码的用户
//		User user = userService.getUserByName(name);
//		
//		if (user != null) {
//			/*
//			 * Object principal = user.getUsername();
//			 * System.out.println(user.getPassword());
//			 */
//			SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(user, // 用户
//					user.getPassword(), // 密码
//					getName() // realm name
//			);
//			
//			return authenticationInfo;
//		}
//			throw new UnknownAccountException();
//		
//		
//	}
//
//	/**
//	 * 授权
//	 */
//	@Override
//	protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
//		return null;
//	}
//}
